<?php
session_start();
include_once "../apps/ManagerIUDS.php";
$managerIUDS = new ManagerIUDS();

$recreationRoomNumber= $_POST["recreation_room_number"];
$recreationRoomDetail= $_POST["recreation_room_detail"];
$recreationRoomLimitWeight = $_POST["recreation_room_limit_weight"];
$price = $_POST["price"];
$isFree= $_POST["is_free"];

$recreationRoomId = $_GET["recreation_room_id"];
if($recreationRoomId == "" || $recreationRoomId == null){
	$recreationRoomId = $_POST["recreation_room_id"];
}

$mode = $_GET["mode"];
if($mode == "" || $mode == null){
	$mode = $_POST["mode"];
}

$page = $_GET['page'];
if (!isset($page) && $page == "") {
	$page = 1;
}

if($mode == "insert"){
	$arrData["recreation_room_number"] = "".$recreationRoomNumber."";
	$arrData["recreation_room_detail"] ="".$recreationRoomDetail."";
	$arrData["recreation_room_limit_weight"] ="".$recreationRoomLimitWeight."";
	$arrData["price"] = "".$price."";
	$arrData["is_free"] = "".$isFree."";
	$arrData["create_date"] = "".date("Y-m-d")."";
	$arrData["create_by"] = "".$_SESSION["user_name"]."";
	$managerIUDS->inserData($arrData, "recreation_room");
	header("Location:../contents/recreation_room_main.php");
}else if($mode == "delete"){
	$arrPrimaryKey["recreation_room_id"] = "".$recreationRoomId."";
	$managerIUDS->deleteData("recreation_room", $arrPrimaryKey, "");
	header("Location:../contents/recreation_room_main.php");
}else if($mode == "update"){
	$arrData["recreation_room_number"] = "".$recreationRoomNumber."";
	$arrData["recreation_room_detail"] ="".$recreationRoomDetail."";
	$arrData["recreation_room_limit_weight"] ="".$recreationRoomLimitWeight."";
	$arrData["price"] = "".$price."";
	$arrData["is_free"] = "".$isFree."";
	$arrData["update_date"] = "".date("Y-m-d")."";
	$arrData["update_by"] = "".$_SESSION["user_name"]."";
	$arrPrimaryKey["recreation_room_id"] = "".$recreationRoomId."";
	//print_r($arrData);
	$managerIUDS->updateData($arrData, "recreation_room", $arrPrimaryKey, "");
	header("Location:../contents/recreation_room_main.php");
}else if($mode == "search"){
	$recreationRoomNumber = $_GET["recreation_room_number"];
	header("Location:../contents/recreation_room_list.php?mode=search&page=".$page."&recreation_room_number=".urlencode($recreationRoomNumber));
}else if($mode == "mainSearch"){
	$recreationRoomNumber = $_GET["recreation_room_number"];
	header("Location:../contents/recreation_room_main.php?mode=search&page=".$page."&recreation_room_number=".urlencode($recreationRoomNumber));
}else if($mode == "listRecreationRoomNumberData"){
	$recreationRoomNumberData = array();
	$recreationRoomNumber = $_GET["recreation_room_number"];
	if($recreationRoomNumber == "" || $recreationRoomNumber == null){
		$recreationRoomNumber = $_POST["recreation_room_number"];
	}
	$recreationRoomNumberData = $managerIUDS->queryData("recreation_room_number", "recreation_room", " WHERE recreation_room_number LIKE '%".$recreationRoomNumber."%'", "2", "");
	echo json_encode($recreationRoomNumberData);

}
?>